package top.gyq2019.controller;

import com.lowagie.text.DocumentException;
import freemarker.template.TemplateException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.gyq2019.utils.PDFUtils;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/img")
    public String img() throws TemplateException, DocumentException, IOException {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "顾健健");
        return PDFUtils.convertFtlToImg(map, "index.ftl", "freemarker-pdf-img", "test-img-" + new Date().getTime(),
                "/templates");
    }

    @GetMapping("/pdf")
    public String pdf() throws TemplateException, DocumentException, IOException {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "顾健健");
        return PDFUtils.convertFtlToPdf(map, "index.ftl", "freemarker-pdf-img", "test-pdf-" + new Date().getTime(),
                "/templates");
    }
}
